#include <pcap.h>
#include <assert.h>

#include "pcap_init.h"

pcap_t *pcap_init(int mode, char *file, char *interface)
{
	pcap_t *pcap_handle = NULL;
	char pcap_error_buffer[PCAP_ERRBUF_SIZE];

	if (mode == 0) {
		assert(file != NULL);
		printf("use pcap file mode.");

		pcap_handle = pcap_open_offline(file, pcap_error_buffer);

		if (pcap_handle == NULL) {
			printf("can't open pcap file. %s", pcap_error_buffer);
		}
		
		return pcap_handle;
	} else if (mode == 1) {
		assert(interface != NULL);
		printf("use pcap live mode.");

		pcap_handle = pcap_open_live(interface, 65536, 1, 1, pcap_error_buffer);
		if (pcap_handle == NULL) {
			printf("can't open pcap device. %s", pcap_error_buffer);
		}

		return pcap_handle;
	} else {
		return NULL;
	}	
}
